
#include "Shape.h"
#include <iostream>
#include <stdlib.h>
#include <stdio.h>

using namespace std;


#define DEBUG_SHAPE_COLOR 9; 
#define COMODIN_SHAPE_COLOR 0; 

Shape::Shape(int c) {
    this->colorsCant = c;
    this->left = DEBUG_SHAPE_COLOR;
    this->top = DEBUG_SHAPE_COLOR;
    this->right = DEBUG_SHAPE_COLOR;
    this->bottom = DEBUG_SHAPE_COLOR;
}
Shape::Shape(int c, int left, int top, int right, int bottom, int id) {
    this->colorsCant = c;
    this->left = left;
    this->top = top;
    this->right = right;
    this->bottom = bottom;
    this->id = id;
}

void Shape::randShape(void) {
    this->left = rand() % this->colorsCant + 1;
    this->top = rand() % this->colorsCant + 1;
    this->right = rand() % this->colorsCant + 1;
    this->bottom = rand() % this->colorsCant + 1;
}

void Shape::debug(void) {
    this->left = DEBUG_SHAPE_COLOR;
    this->top = DEBUG_SHAPE_COLOR;
    this->right = DEBUG_SHAPE_COLOR;
    this->bottom = DEBUG_SHAPE_COLOR;
}

void Shape::comodin(void) {
    this->left = COMODIN_SHAPE_COLOR;
    this->top = COMODIN_SHAPE_COLOR;
    this->right = COMODIN_SHAPE_COLOR;
    this->bottom = COMODIN_SHAPE_COLOR;
}

bool Shape::esComodin(void) {
    bool ret;
    ret = this->left == COMODIN_SHAPE_COLOR;
    //and this->top == COMODIN_SHAPE_COLOR and  this->bottom == COMODIN_SHAPE_COLOR and  this->right == COMODIN_SHAPE_COLOR);
    //printf("entro a es comodin %d %d %d %d|  %d", this->left, this->top, this->right, this->bottom, ret);
    return ret;
}

bool Shape::esDebug(void) {
    return this->left == this->top == this->bottom == this->right == DEBUG_SHAPE_COLOR;
}

bool Shape::fichaEncaja(Shape* left, Shape* top) {
    return (this->left == left->right or
            this->left == 0 or
            left->right == 0) and
            (this->top == top->bottom or
            this->top == 0 or
            top->bottom == 0);
}

Shape::Shape(const Shape& orig) {
    this->left = orig.left;
    this->right = orig.right;
    this->top = orig.top;
    this->bottom = orig.bottom;
    this->colorsCant = orig.colorsCant;
}

Shape::~Shape() {
}

ostream& operator<<(ostream& stdout, Shape &s) {
    char buffer[20];
    sprintf(buffer, " %d | %d | %d | %d \n", s.left, s.top, s.right, s.bottom);
    stdout << buffer;
    return stdout;
}
